package com.example.a2032.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.a2032.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SettingAdapter extends RecyclerView.Adapter {
    int[] itemImgId;
    String[] itemName;


    public SettingAdapter(String[] itemName, int[] itemImgId) {
        this.itemImgId = itemImgId;
        this.itemName = itemName;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new SettingViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_setting, parent, false));
    }


    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        SettingViewHolder settingViewHolder=(SettingViewHolder)holder;
        settingViewHolder.tvSettingItem.setText(itemName[position]);
        settingViewHolder.ivSettingItem.setImageResource(itemImgId[position]);
        settingViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(itemClickListener!=null)itemClickListener.onItemClick(itemName[position]);
            }
        });
    }

    @Override
    public int getItemCount() {
        return itemName.length;
    }

    static class SettingViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_setting_item)
        ImageView ivSettingItem;
        @BindView(R.id.tv_setting_item)
        TextView tvSettingItem;
        public SettingViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
    onItemClickListener itemClickListener;
    public void setOnItemClickListener(onItemClickListener itemClickListener){
        this.itemClickListener=itemClickListener;
    }
    public interface onItemClickListener{
        public void onItemClick(String title);
    }
}
